﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using OgilvyOne.Model;
using OgilvyOne.BLL;

public partial class admin_manager_modellabel_add :AdminBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            header.Text = new ColumnBll().LayeridSysColumnNaiv(Layerid);
            this.PopedomValidate(layerid, ADD);
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        TemplateLabelModel model = new TemplateLabelModel();
        if (labelename.Value.ToString().Trim()== null || labelename.Value.ToString().Trim().ToString() == "")
        {
            Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), Guid.NewGuid().ToString(), "alert('模板名称不能为空！');", true);
            return;
        }
        if (def.Value.ToString().Trim() == null || def.Value.ToString().Trim() == "")
        {
            Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), Guid.NewGuid().ToString(), "alert('模板定义不能为空！');", true);
            return;
        }
        if (value.Value.ToString().Trim() == null || value.Value.ToString().Trim() == "")
        {
            Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), Guid.NewGuid().ToString(), "alert('模板值不能为空！');", true);
            return;
        }
        model.Addtime = DateTime.Now;
        model.Def = def.Value.ToString().Trim();
        model.Name = labelename.Value.ToString().Trim();
        model.Value = value.Value.ToString().Trim();
        model.LabelType = labeltype.Text;
       
        TemplateLabelBll bll = new TemplateLabelBll();
        if (!bll.Exists(model.Name,0))
        {
            if (new TemplateLabelBll().Add(model))
            {
                string user = new AdminBasePage().GetSessionUsersModel().Username;
                this.insertLog(user + "添加模板标签名称： " + labelename.Value + "模板标签定义：" + def.Value + "模板标签值： " + value.Value);
                Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), Guid.NewGuid().ToString(), "alert('添加成功！');window.location=\"modellabel_manage.aspx?layerid=" + Layerid + "\"", true);

            }
            else
            {
                Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), Guid.NewGuid().ToString(), "alert('添加失败！');window.location=\"modellabel_manage.aspx?layerid=" + Layerid + "\"", true);
            }
        }
        else
            Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), Guid.NewGuid().ToString(), "alert('模板标签名已存在！');", true);
        return;

    }
}
